home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2007 June / SAN CD 6-2007 CD-ROM 25.iso / pc / Software / AstroGrav_Win / Java / jre1.6.0 / lib / rt.jar / sun / text / UCompactIntArray.class (.txt) < prev   
Encoding:
Java Class File  |  2006-11-29  |  1.8 KB  |  155 lines

  1. package sun.text;
  2.  
  3. public final class UCompactIntArray implements Cloneable {
  4.    private static final int PLANEMASK = 196608;
  5.    private static final int PLANESHIFT = 16;
  6.    private static final int PLANECOUNT = 16;
  7.    private static final int CODEPOINTMASK = 65535;
  8.    private static final int UNICODECOUNT = 65536;
  9.    private static final int BLOCKSHIFT = 7;
  10.    private static final int BLOCKCOUNT = 128;
  11.    private static final int INDEXSHIFT = 9;
  12.    private static final int INDEXCOUNT = 512;
  13.    private static final int BLOCKMASK = 127;
  14.    private int defaultValue;
  15.    private int[][] values;
  16.    private short[][] indices;
  17.    private boolean isCompact;
  18.    private boolean[][] blockTouched;
  19.    private boolean[] planeTouched;
  20.  
  21.    public UCompactIntArray() {
  22.       this.values = new int[16][];
  23.       this.indices = new short[16][];
  24.       this.blockTouched = new boolean[16][];
  25.       this.planeTouched = new boolean[16];
  26.    }
  27.  
  28.    public UCompactIntArray(int var1) {
  29.       this();
  30.       this.defaultValue = var1;
  31.    }
  32.  
  33.    public int elementAt(int var1) {
  34.       int var2 = (var1 & 196608) >> 16;
  35.       if (!this.planeTouched[var2]) {
  36.          return this.defaultValue;
  37.       } else {
  38.          var1 &= 65535;
  39.          return this.values[var2][(this.indices[var2][var1 >> 7] & '\uffff') + (var1 & 127)];
  40.       }
  41.    }
  42.  
  43.    public void setElementAt(int var1, int var2) {
  44.       if (this.isCompact) {
  45.          this.expand();
  46.       }
  47.  
  48.       int var3 = (var1 & 196608) >> 16;
  49.       if (!this.planeTouched[var3]) {
  50.          this.initPlane(var3);
  51.       }
  52.  
  53.       var1 &= 65535;
  54.       this.values[var3][var1] = var2;
  55.       this.blockTouched[var3][var1 >> 7] = true;
  56.    }
  57.  
  58.    public void compact() {
  59.       if (!this.isCompact) {
  60.          for(int var1 = 0; var1 < 16; ++var1) {
  61.             if (this.planeTouched[var1]) {
  62.                int var2 = 0;
  63.                int var3 = 0;
  64.                short var4 = -1;
  65.  
  66.                for(int var5 = 0; var5 < this.indices[var1].length; var3 += 128) {
  67.                   this.indices[var1][var5] = -1;
  68.                   if (!this.blockTouched[var1][var5] && var4 != -1) {
  69.                      this.indices[var1][var5] = var4;
  70.                   } else {
  71.                      int var6 = var2 * 128;
  72.                      if (var5 > var2) {
  73.                         System.arraycopy(this.values[var1], var3, this.values[var1], var6, 128);
  74.                      }
  75.  
  76.                      if (!this.blockTouched[var1][var5]) {
  77.                         var4 = (short)var6;
  78.                      }
  79.  
  80.                      this.indices[var1][var5] = (short)var6;
  81.                      ++var2;
  82.                   }
  83.  
  84.                   ++var5;
  85.                }
  86.  
  87.                int var7 = var2 * 128;
  88.                int[] var8 = new int[var7];
  89.                System.arraycopy(this.values[var1], 0, var8, 0, var7);
  90.                this.values[var1] = var8;
  91.                this.blockTouched[var1] = null;
  92.             }
  93.          }
  94.  
  95.          this.isCompact = true;
  96.       }
  97.    }
  98.  
  99.    private void expand() {
  100.       if (this.isCompact) {
  101.          for(int var3 = 0; var3 < 16; ++var3) {
  102.             if (this.planeTouched[var3]) {
  103.                this.blockTouched[var3] = new boolean[512];
  104.                int[] var2 = new int[65536];
  105.  
  106.                for(int var1 = 0; var1 < 65536; ++var1) {
  107.                   var2[var1] = this.values[var3][this.indices[var3][var1 >> 7] & '\uffff' + (var1 & 127)];
  108.                   this.blockTouched[var3][var1 >> 7] = true;
  109.                }
  110.  
  111.                for(int var4 = 0; var4 < 512; ++var4) {
  112.                   this.indices[var3][var4] = (short)(var4 << 7);
  113.                }
  114.  
  115.                this.values[var3] = var2;
  116.             }
  117.          }
  118.  
  119.          this.isCompact = false;
  120.       }
  121.  
  122.    }
  123.  
  124.    private void initPlane(int var1) {
  125.       this.values[var1] = new int[65536];
  126.       this.indices[var1] = new short[512];
  127.       this.blockTouched[var1] = new boolean[512];
  128.       this.planeTouched[var1] = true;
  129.       if (this.planeTouched[0] && var1 != 0) {
  130.          System.arraycopy(this.indices[0], 0, this.indices[var1], 0, 512);
  131.       } else {
  132.          for(int var2 = 0; var2 < 512; ++var2) {
  133.             this.indices[var1][var2] = (short)(var2 << 7);
  134.          }
  135.       }
  136.  
  137.       for(int var3 = 0; var3 < 65536; ++var3) {
  138.          this.values[var1][var3] = this.defaultValue;
  139.       }
  140.  
  141.    }
  142.  
  143.    public int getKSize() {
  144.       int var1 = 0;
  145.  
  146.       for(int var2 = 0; var2 < 16; ++var2) {
  147.          if (this.planeTouched[var2]) {
  148.             var1 += this.values[var2].length * 4 + this.indices[var2].length * 2;
  149.          }
  150.       }
  151.  
  152.       return var1 / 1024;
  153.    }
  154. }
  155.